<template>
	<view class="" style="background-color: #d70127;">
		<view class="content">
			<view class="codebox">
				<image :src="mainData.recQcCode" mode=""></image>
				<view class="" style="display: flex;justify-content: center;align-items: center;">
					<view class="codefont">
						{{mainData.recCode}}
					</view>
					<image src="/static/image/copy.png" mode="widthFix" style="width: 60rpx;margin-left: 20rpx;"
						@click="$copy(mainData.recCode)"></image>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		selectByUserId
	} from '../request/api.js'
	export default {
		data() {
			return {
				mainData: {},
				imglink: "",
				bindCode: ""
			};
		},
		onLoad() {
			this.getmyRecommendCode();
			this.getMa()
		},
		methods: {
			// 获取二维码
			getMa() {
				let that = this;
				selectByUserId({
					userId: uni.getStorageSync('userInfo').id
				}).then(res => {
					if (res.code == 200) {
						that.mainData = res.result;
					}
				})
			},
			pre() {
				let demo = []
				demo.push(this.imglink)
				uni.previewImage({
					urls: demo,
					longPressActions: {
						itemList: ['保存图片'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			//手动绑定
			bind() {
				// getMemberByRecCode({
				// 	recCode: this.bindCode
				// }).then(res => {
				// 	if (res.success) {
				// 		bindRecommendShip({
				// 			masterId: res.result.id,
				// 			memberId: uni.getStorageSync('userInfo').id
				// 		}).then(data => {
				// 			if (data.code == 200) {
				// 				uni.showToast({
				// 					title: data.result,
				// 					icon: 'none'
				// 				})
				// 			} else {
				// 				uni.showToast({
				// 					title: data.message,
				// 					icon: 'none'
				// 				})
				// 			}
				// 		})
				// 	}
				// })
			},
			//复制推广码
			copy() {
				uni.setClipboardData({
					data: this.mainData.recInfo.recCode,
					success: function() {
						uni.showToast({
							icon: 'none',
							title: '复制成功'
						});
					}
				});
			},
			getmyRecommendCode() {
				// myRecommendCode({
				// 	memberId: uni.getStorageSync('userInfo').id,
				// }).then(res => {
				// 	if (res.code == 200) {
				// 		// console.log(res)
				// 		this.mainData = res.result;
				// 		this.imglink = 'data:image/png;base64,' + res.result.recInfo.recQcCode;
				// 	}
				// })
			},
		},
	}
</script>
<style lang="scss" scoped>
	.content {
		height: 100vh;
		background: url('/static/image/bg.png') no-repeat center center;
		background-size: 100% 100%;
		overflow: hidden;

		.codebox {
			width: 660rpx;
			border-radius: 40rpx;
			padding: 60rpx;
			box-sizing: border-box;
			text-align: center;
			background: #fff;
			margin: 200rpx auto;

			image {
				width: 536rpx;
				height: 536rpx;
			}

			.codefont {
				font-size: 48rpx;
				color: #000;
			}
		}

		.share {
			width: 698rpx;
			height: 104rpx;
			line-height: 104rpx;
			border-radius: 148px;
			color: #fff;
			background: #3570D6;
			margin: 80rpx auto;
		}
	}

	.inputTui {
		height: 88rpx;
		border: 1px solid #ccc;
		width: 410rpx;
		margin-left: 40rpx;
		border-radius: 20rpx;
		padding: 0 20rpx;
		color: #FFF;
	}
</style>